/*
 * Created on 2006-2-15
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package com.hitrust.gs.business;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;

import system.LoginContext;

import com.hitrust.gs.bean.GSManufactureBean;
import com.hitrust.gs.bean.GSOperatorBean;
import com.hitrust.gs.bean.GSOrderAnaDetailBean;
import com.hitrust.gs.bean.GSOrderBean;
import com.hitrust.gs.bean.GSOrderDetailBean;
import com.hitrust.gs.bean.GSProductStorageApepBean;
import com.hitrust.gs.bean.GSProviderBean;
import com.hitrust.gs.dao.GSOperatorDAO;
import com.hitrust.gs.dao.GSOrderDAO;
import com.hitrust.gs.dao.GSOrderDetailDAO;
import com.hitrust.gs.dao.GSOrganizationDAO;
import com.hitrust.gs.dao.GSProductStorageDao;
import com.hitrust.gs.dao.GSProviderDAO;
import com.hitrust.gs.dao.GSTempOrderDAO;
import com.hitrust.gs.lib.GSBaseConstants;
import com.hitrust.gs.lib.GSLogWriter;
import com.hitrust.gs.service.GSBaseManager;
import com.hitrust.gs.service.GSBaseProcesser;
import com.hitrust.gs.util.DefineDic;
import com.hitrust.gs.util.date.DateUtil;
import com.hitrust.gs.util.exception.GSException;
import com.hitrust.gs.util.lang.IDGenerator;
import com.hitrust.gs.util.lang.StringUtils;
import com.hitrust.gs.vo.GSDeliverOrderSaveVO;
import com.hitrust.gs.vo.GSOrderAuditQueryVO;
import com.hitrust.gs.vo.GSOrderAuditVO;
import com.hitrust.gs.vo.GSOrderAuthorizeVO;
import com.hitrust.gs.vo.GSOrderModifyQueryVO;
import com.hitrust.gs.vo.GSOrderModifySaveVO;
import com.hitrust.gs.vo.GSOrderReceiveQueryVO;
import com.hitrust.gs.vo.GSOrderSubmitVO;
import com.hitrust.gs.vo.GSOrderTempManufactureVO;
import com.hitrust.gs.vo.GSOrderVO;

/**
 * @author simonyi
 * 
 * TODO To change the template for this generated type comment go to Window -
 * Preferences - Java - Code Style - Code Templates
 */
public class GSOrderProcesser implements GSBaseProcesser {
    
    public static String aSql =" select det.*,"
        +" ord.gs_authorize_date as gs_authorize_date_order,"
        +" ord.gs_authorizer_id as gs_authorizer_id_order,"
        +" ord.gs_balance_mode as gs_balance_mode_order,"
        +" ord.gs_deliver_goods_addr, "
        +" ord.gs_deliver_mode, "
        +" ord.gs_firstaudit_advices, "
        +" ord.gs_firstaudit_date,"
        +" ord.gs_firstauditor_id,"
        +" ord.gs_lastmodifer_id as gs_lastmodifer_id_order,"
        +" ord.gs_lastmodify_contents as gs_lastmodify_contents_order,"
        +" ord.gs_lastmodify_date as gs_lastmodify_date_order,"
        +" ord.gs_notes,"
        +" ord.gs_order_category, "
        +" ord.gs_order_contact_name, "
        +" ord.gs_order_contact_phone,"
        +" ord.gs_order_create_date,"
        +" ord.gs_order_status, "
        +" ord.gs_order_sum,"
        +" ord.gs_order_system_create_date, "
        +" ord.gs_order_tempid as gs_order_tempid_order,"
        +" ord.gs_recorder_id,"
        +" ord.gs_review_advices, "
        +" ord.gs_review_date,"
        +" ord.gs_reviewer_id,"
        +" ord.gs_submit_date1, "
        +" ord.gs_submit_date2 as gs_submit_date2_order,"
        +" ord.gs_submiter_id1, "
        +" ord.gs_submiter_id2 as gs_submiter_id2_order,"
        +" ord.gs_workcorp_id,"
        +" pro.adapt_machine_type,"
        +" pro.apep_code, "
        +" pro.appender_property, "
        +" pro.area,"
        +" pro.balance_customer_code, "
        +" pro.balance_mode,"
        +" pro.category_code, "
        +" pro.concentricity_code,"
        +" pro.create_time as create_time_product,"
        +" pro.create_user as create_user_product,"
        +" pro.create_user_id as create_user_id_product,"
        +" pro.drawing_piece_code,"
        +" pro.id as id_product,"
        +" pro.is_buy,"
        +" pro.is_normal, "
        +" pro.is_tradeflat_product,"
        +" pro.last_update_time as last_update_time_product,"
        +" pro.last_update_user as last_update_user_product,"
        +" pro.last_update_user_id as last_update_user_id_product,"
        +" pro.manufaturer, "
        +" pro.model, "
        +" pro.name as name_product,"
        +" pro.old_apep_code, "
        +" pro.pic, "
        +" pro.product_brand, "
        +" pro.product_unit,"
        +" pro.provider_code, "
        +" pro.quality_assure_period, "
        +" pro.recent_adjusted_price, "
        +" pro.recent_adjustprice_date, "
        +" pro.record_date, "
        +" pro.recorder_id, "
        +" pro.remark as remark_product,"
        +" pro.spec,"
        +" pro.status as status_product,"
        +" pro.unit_price,"
        +" pro.warehouse_code,"
        +" pro.warehouse_name,pro.is_update,"
        +" prv.*, "
        +" war.address as address_warehouse,"
        +" war.agent_flag,"
        +" war.code as code_warehouse,"
        +" war.contack_tel, "
        +" war.contact_person,"
        +" war.create_time as create_time_warehouse,"
        +" war.create_user as create_user_warehouse,"
        +" war.create_user_id as create_user_id_warehouse,"
        +" war.display_order, "
        +" war.full_name as full_name_warehouse,"
        +" war.id as id_warehouse,"
        +" war.is_show, "
        +" war.last_update_time as last_update_time_warehouse,"
        +" war.last_update_user as last_update_user_warehouse,"
        +" war.last_update_user_id as last_update_user_id_warehouse,"
        +" war.name as name_warehouse,"
        +" war.remark,"
        +" war.status as status_warehouse "
        +" from gs_order ord, gs_order_detail det, t_product pro, t_warehouse war,t_provider prv"
        +" where"
        +" ord.gs_order_tempid = det.gs_order_tempid"
        +" and det.gs_concentricity_id = pro.concentricity_code "
        +" and det.gs_manufacture_id = pro.apep_code"
        +" and ord.gs_workcorp_id = war.code"
        +" and pro.provider_code = prv.code ";
    
    public static String userSql =" select det.*,"
        +" ord.gs_authorize_date as gs_authorize_date_order,"
        +" ord.gs_authorizer_id as gs_authorizer_id_order,"
        +" ord.gs_balance_mode as gs_balance_mode_order,"
        +" ord.gs_deliver_goods_addr, "
        +" ord.gs_deliver_mode, "
        +" ord.gs_firstaudit_advices, "
        +" ord.gs_firstaudit_date,"
        +" ord.gs_firstauditor_id,"
        +" ord.gs_lastmodifer_id as gs_lastmodifer_id_order,"
        +" ord.gs_lastmodify_contents as gs_lastmodify_contents_order,"
        +" ord.gs_lastmodify_date as gs_lastmodify_date_order,"
        +" ord.gs_notes,"
        +" ord.gs_order_category, "
        +" ord.gs_order_contact_name, "
        +" ord.gs_order_contact_phone,"
        +" ord.gs_order_create_date,"
        +" ord.gs_order_status, "
        +" ord.gs_order_sum,"
        +" ord.gs_order_system_create_date, "
        +" ord.gs_order_tempid as gs_order_tempid_order,"
        +" ord.gs_recorder_id,"
        +" ord.gs_review_advices, "
        +" ord.gs_review_date,"
        +" ord.gs_reviewer_id,"
        +" ord.gs_submit_date1, "
        +" ord.gs_submit_date2 as gs_submit_date2_order,"
        +" ord.gs_submiter_id1, "
        +" ord.gs_submiter_id2 as gs_submiter_id2_order,"
        +" ord.gs_recorder_id,"
        +" ord.gs_workcorp_id,"
        +" pro.adapt_machine_type,"
        +" pro.apep_code, "
        +" pro.appender_property, "
        +" pro.area,"
        +" pro.balance_customer_code, "
        +" pro.balance_mode,"
        +" pro.category_code, "
        +" pro.concentricity_code,"
        +" pro.create_time as create_time_product,"
        +" pro.create_user as create_user_product,"
        +" pro.create_user_id as create_user_id_product,"
        +" pro.drawing_piece_code,"
        +" pro.id as id_product,"
        +" pro.is_buy,"
        +" pro.is_normal, "
        +" pro.is_tradeflat_product,"
        +" pro.last_update_time as last_update_time_product,"
        +" pro.last_update_user as last_update_user_product,"
        +" pro.last_update_user_id as last_update_user_id_product,"
        +" pro.manufaturer, "
        +" pro.model, "
        +" pro.name as name_product,"
        +" pro.old_apep_code, "
        +" pro.pic, "
        +" pro.product_brand, "
        +" pro.product_unit,"
        +" pro.provider_code, "
        +" pro.quality_assure_period, "
        +" pro.recent_adjusted_price, "
        +" pro.recent_adjustprice_date, "
        +" pro.record_date, "
        +" pro.recorder_id, "
        +" pro.remark as remark_product,"
        +" pro.spec,"
        +" pro.status as status_product,"
        +" pro.unit_price,"
        +" pro.warehouse_code,"
        +" pro.warehouse_name,pro.is_update,"
        +" prv.*, "
        +" war.address as address_warehouse,"
        +" war.agent_flag,"
        +" war.code as code_warehouse,"
        +" war.contack_tel, "
        +" war.contact_person,"
        +" war.create_time as create_time_warehouse,"
        +" war.create_user as create_user_warehouse,"
        +" war.create_user_id as create_user_id_warehouse,"
        +" war.display_order, "
        +" war.full_name as full_name_warehouse,"
        +" war.id as id_warehouse,"
        +" war.is_show, "
        +" war.last_update_time as last_update_time_warehouse,"
        +" war.last_update_user as last_update_user_warehouse,"
        +" war.last_update_user_id as last_update_user_id_warehouse,"
        +" war.name as name_warehouse,"
        +" war.remark,"
        +" war.status as status_warehouse "
        +" from gs_order ord, gs_order_detail det, t_product pro, t_warehouse war,t_provider prv"
        +" where"
        +" ord.gs_order_tempid = det.gs_order_tempid"
        +" and det.gs_concentricity_id = pro.concentricity_code "
        +" and det.gs_manufacture_id = pro.apep_code"
        +" and ord.gs_workcorp_id = war.code"
        +" and pro.provider_code = prv.code ";
    /**
     * 获得当前操作员录入的/初审未通过的订单
     * 
     * @param bean
     * @return
     * @throws GSException
     */
    public ArrayList getAllModifiableByRecoder(GSOperatorBean bean, GSOrderVO vo, String sqlCondition) throws GSException {

        GSOrderDAO ordd = new GSOrderDAO();
        String sql = "select * from gs_order where gs_rocoder_id=? and gs_order_status = ? or gs_order_status = ? " + sqlCondition;

        Object[] obj = { bean.getGs_oper_id(), "1", "4" };
        ArrayList orderList = null;
        try {
            orderList = ordd.executeQuery(new GSOrderBean(), sql, null);

        } catch (Exception e) {
            throw new GSException(GSException.E19999, GSException.E19999_MSG);
        }
        return orderList;

    }

    /**
     * 得到所有需要审核的订单
     * 
     * @param operatorId
     *            操作员id
     * @param operOrgId
     *            操作员所属机构
     * @param orderId
     * @param orderCategory
     * @param workCorpId
     * @return 订单bean对象
     * @throws GSException
     */
    public ArrayList getAllAuthorizeNeedOrder(String operatorId, String operOrgId, String orderId, String orderCategory, String workCorpId) throws GSException {
        GSOrderDAO ordd = new GSOrderDAO();
        GSOperatorDAO operd = new GSOperatorDAO();

        if (operOrgId == null || operOrgId.length() == 0 || operatorId == null)
            throw new GSException(GSException.E10001, GSException.E10001_MSG);

        // 保护性代码
        // 如果操作员所属的机构不是巴士物资或巴士物资部门，则该人所能审核的订单数为零
        if (!"00".equals(operOrgId.substring(0, 2))) {
            return new ArrayList();
        }

        // 构造订单查询语句,条件:输入条件+订单类型不为'补单'+(状态为'已提交' or (状态为'已申请' + 输入公司为'00*' +
        // 录入人员不是自己))
        String sql = "select * from GS_ORDER where gs_order_category <> 3 and (gs_order_status=6 or ( gs_order_status=1 and gs_workcorp_id like '00*' and gs_recoder_id <> '"
                + operatorId + "')) ";
        if (orderId != null && orderId.length() != 0) {
            sql += " and gs_order_tempid like '%" + orderId + "%' ";
        }
        if (orderCategory != null && orderCategory.length() != 0) {
            sql += " and gs_order_category = '" + orderCategory + "' ";
        }
        if (workCorpId != null && workCorpId.length() != 0) {
            sql += " and gs_workcorp_id = '" + workCorpId + "'";
        }

        sql += " order by gs_order_tempid desc";
        // 执行订单查询,得到订单信息，包括订单号、产品代号和申请人代号
        ArrayList orderList = null;
        try {
            orderList = ordd.executeQuery(new GSOrderBean(), sql, null);

        } catch (Exception e) {
            throw new GSException(GSException.E19999, GSException.E19999_MSG);
        }

        return orderList;
    }

    private StringBuffer getModifyNeedSql(GSOrderModifyQueryVO vo) throws GSException {
        StringBuffer tSql = new StringBuffer(aSql);

        if (vo.orderId != null && vo.orderId.length() != 0) {
            tSql.append(" and ord.GS_ORDER_TEMPID like '%" + vo.orderId.trim() + "%'");
        }
        if (vo.detailStatus == null || vo.detailStatus.length() == 0) {
            tSql.append(" and det.GS_ORDER_DETAIL_STATUS in('1','2','3','4','5','6','8','11') ");
        } else {
            tSql.append(" and det.GS_ORDER_DETAIL_STATUS ='" + vo.detailStatus + "' ");
        }

        if(vo.deptId!=null){
            tSql.append(" and ord.GS_WORKCORP_ID  like '" + vo.deptId + "%'");
        }
        if (vo.concentricityId != null) {
            tSql.append(" and det.GS_CONCENTRICITY_ID like '%" + vo.concentricityId.trim() + "%'");
        }
        if (vo.manufInfo != null) {
            tSql.append(" and (pro.NAME like '%" + vo.manufInfo.trim() + "%'");
            tSql.append(" or pro.MODEL like '%" + vo.manufInfo.trim() + "%'");
            tSql.append(" or pro.SPEC like '%" + vo.manufInfo.trim() + "%'");
            tSql.append(" or pro.PRODUCT_BRAND like '%" + vo.manufInfo.trim() + "%'");
            tSql.append(" or pro.APPENDER_PROPERTY like '%" + vo.manufInfo.trim() + "%'");
            tSql.append(" or pro.MANUFATURER like '%" + vo.manufInfo.trim() + "%')");
        }
        if (vo.beginDate != null && !"".equals(vo.beginDate)) {
            tSql.append(" and to_char(to_date(ord.GS_ORDER_CREATE_DATE,'YYYY-MM-DD HH24:mi:ss'),'YYYY-MM-DD') >='" + vo.beginDate.replace('/', '-') + "'");
        }
        if (vo.endDate != null && !"".equals(vo.endDate)) {
            tSql.append(" and to_char(to_date(ord.GS_ORDER_CREATE_DATE,'YYYY-MM-DD HH24:mi:ss'),'YYYY-MM-DD') <='" + vo.endDate.replace('/', '-') + "'");
        }
        //图件号
        if(vo.drawingpiececode != null && !vo.drawingpiececode.equals("")){
                    tSql.append(" and pro.DRAWING_PIECE_CODE like '%" + vo.drawingpiececode.trim() + "%'");
                }
        tSql.append(" and pro.is_buy='1' order by det.GS_LASTMODIFY_DATE desc");
        GSLogWriter.debug(this, tSql.toString());

        return tSql;
    }

    public int getModifyNeedOrderCount(GSOrderModifyQueryVO vo) throws GSException {
        GSOrderDAO ordd = new GSOrderDAO();
        // 取得查询SQL
        String tSql = this.getModifyNeedSql(vo).toString();
        tSql = "select count(*) from(" + tSql + ")";
        try {
            return ordd.queryRowNum(tSql, null);
        } catch (Exception ex) {
            GSLogWriter.error(this, ex.toString());
            throw new GSException(GSException.E19999, GSException.E19999_MSG);
        }
    }

    /**
     * 得到所有需要修改的订单号
     * 
     * @param operatorId
     *            操作员id
     * @param operOrgId
     *            操作员所属机构id
     * @param orderId
     *            订单号，来自查询条件
     * @param orderCategory
     *            订单类型，来自查询条件
     * @param workCorpId
     *            下单机构，来自查询条件
     * @return 订单号列表
     * @throws GSException
     */
    public ArrayList getModifyNeedOrder(GSOrderModifyQueryVO vo, int pageNo, int pageSize) throws GSException {

        GSOrderDAO ordd = new GSOrderDAO();
        StringBuffer tSql = this.getModifyNeedSql(vo);

        // 执行订单查询,得到订单信息，包括订单号、产品代号和申请人代号
        ArrayList orderList = null;
        try {
            orderList = ordd.executeQuery(new GSOrderAnaDetailBean(), tSql.toString(), null, pageNo, pageSize);

        } catch (Exception e) {
            throw new GSException(GSException.E19999, GSException.E19999_MSG);
        }

        // 得到最后的订单列表
        return orderList;
    }

    /** 初审订单    条件:状态为'已申请'+申请人不是自己*/
    public String getAllAuditNeedOrderSql(LoginContext operBean, GSOrderAuditQueryVO vo) {
        StringBuffer tSql = new StringBuffer();
        //为满足测试,暂时不限制申请人条件
        //tSql.append(" and ord.GS_RECORDER_ID <> '"+operBean.getLoginUserId()+"%'");
        tSql.append(" and ord.GS_ORDER_STATUS ='1' and det.GS_ORDER_DETAIL_STATUS <> '21'");
        if (vo.orderId != null && vo.orderId.trim().length() > 0) {
            tSql.append(" and ord.GS_ORDER_TEMPID like '%" + vo.orderId.trim() + "%'");
        }
        if (vo.deptId != null && vo.deptId.trim().length() > 0) {
            tSql.append(" and ord.GS_WORKCORP_ID like'" + vo.deptId + "%'");
        }
        if (vo.concentricityId != null && vo.concentricityId.trim().length() > 0) {
            tSql.append(" and det.GS_CONCENTRICITY_ID like '%" + vo.concentricityId.trim() + "%'");
        }
        if (vo.manufInfo != null && vo.manufInfo.trim().length() > 0) {
            tSql.append(" and (pro.NAME like '%" + vo.manufInfo.trim() + "%'");
            tSql.append(" or pro.MODEL like '%" + vo.manufInfo.trim() + "%'");
            tSql.append(" or pro.SPEC like '%" + vo.manufInfo.trim() + "%'");
            tSql.append(" or pro.PRODUCT_BRAND like '%" + vo.manufInfo.trim() + "%'");
            tSql.append(" or pro.APPENDER_PROPERTY like '%" + vo.manufInfo.trim() + "%'");
            tSql.append(" or pro.MANUFATURER like '%" + vo.manufInfo.trim() + "%')");
        }
        if (!"".equals(vo.beginDate)) {
            tSql.append(" and to_char(to_date(ord.GS_ORDER_CREATE_DATE,'YYYY-MM-DD HH24:mi:ss'),'YYYY-MM-DD') >='" + vo.beginDate.replace('/', '-') + "'");
        }
        if (!"".equals(vo.endDate)) {
            tSql.append(" and to_char(to_date(ord.GS_ORDER_CREATE_DATE,'YYYY-MM-DD HH24:mi:ss'),'YYYY-MM-DD') <='" + vo.endDate.replace('/', '-') + "'");
        }
        //查询图件号
        if(vo.drawingpiececode != null && !vo.drawingpiececode.equals("")){
            tSql.append(" and pro.DRAWING_PIECE_CODE like '%" + vo.drawingpiececode.trim() + "%'");
        }
        tSql.append(" order by ord.GS_ORDER_CREATE_DATE desc");
        String sqls = this.aSql + tSql.toString();
        GSLogWriter.debug(this, sqls);
        return sqls;
    }

    public int getAllAuditNeedOrderCount(LoginContext operBean, GSOrderAuditQueryVO vo) throws GSException {
        GSOrderDAO ordd = new GSOrderDAO();
        GSOperatorDAO operd = new GSOperatorDAO();

        if (vo.deptId == null || vo.deptId.length() == 0 || vo.deptId == null)
            throw new GSException(GSException.E10001, GSException.E10001_MSG);

        String tSql = new StringBuffer("select count(*) from (").append(getAllAuditNeedOrderSql(operBean, vo)).append(")").toString();
        ArrayList orderList = null;
        try {
            return ordd.queryRowNum(tSql, null);

        } catch (Exception e) {
            throw new GSException(GSException.E19999, GSException.E19999_MSG);
        }
    }

    /**
     * 得到所有需要初审的订单号
     * 
     * @param operatorId
     *            操作员id
     * @param operOrgId
     *            操作员所属机构id
     * @param orderId
     *            订单号，来自查询条件
     * @param orderCategory
     *            订单类型，来自查询条件
     * @param workCorpId
     *            下单机构，来自查询条件
     * @return 订单号列表
     * @throws GSException
     */
    public ArrayList getAllAuditNeedOrder(LoginContext operBean, GSOrderAuditQueryVO vo) throws GSException {
        GSOrderDAO ordd = new GSOrderDAO();
        if (vo.deptId == null || vo.deptId.length() == 0 || vo.deptId == null)
            throw new GSException(GSException.E10001, GSException.E10001_MSG);
        String tSql = getAllAuditNeedOrderSql(operBean, vo);
        // 执行订单查询,得到订单信息，包括订单号、产品代号和申请人代号
        ArrayList orderList = new ArrayList();
        try {
            orderList = ordd.executeQuery(new GSOrderAnaDetailBean(), tSql.toString(), null);
        } catch (Exception e) {
            throw new GSException(GSException.E10041, GSException.E10041_MSG);
        }
        // 根据过滤得有效订单组织订单显示对象
        ArrayList tList = new ArrayList();
        if (orderList.size() > 0) {
            String tOrderId = "";
            GSOrderVO tGSOrderVO = null;
            for (int i = 0; i < orderList.size(); i++) {
                GSOrderAnaDetailBean tGSOrderAuditViewVO = (GSOrderAnaDetailBean) orderList.get(i);
                String m = DefineDic.getBalanceMode(tGSOrderAuditViewVO.getGs_balance_mode());
                // 判断新取得的OrderSubmitVO对象中的订单编号是否与前一对象中订单编号相同
                if (tOrderId.equals(tGSOrderAuditViewVO.getGs_order_tempid_order())) {
                    // 订单编号相同则将取得的产品信息放入同一订单VO对象的ArrayList对象中
                    String[] tStr = new String[13];
                    tStr[0] = tGSOrderAuditViewVO.getGs_concentricity_id();
                    tStr[1] = tGSOrderAuditViewVO.getName_product();
                    // tStr[2] =
                    // StringUtils.formatEDouble(tGSOrderAuditViewVO.manufacutreUnitPrice,2);
                    tStr[2] = tGSOrderAuditViewVO.getSpec();
                    tStr[3] = tGSOrderAuditViewVO.getModel();
                    tStr[4] = tGSOrderAuditViewVO.getProduct_brand();
                    tStr[5] = StringUtils.format(tGSOrderAuditViewVO.getGs_order_count(), 2) + tGSOrderAuditViewVO.getProduct_unit();
                    // tStr[4] =
                    // StringUtils.formatEDouble(tGSOrderAuditViewVO.manufacutreUnitPrice
                    // * tGSOrderAuditViewVO.orderCount,2);
                    // tStr[5] =
                    // GSBaseManager.getOrderDeptName(tGSOrderAuditViewVO.orderDeptId);
                    // tStr[6] =
                    // GSBaseManager.getProviderName(tGSOrderAuditViewVO.providerName);
                    tStr[6] = tGSOrderAuditViewVO.getGs_order_detail_id();
                    tStr[7] = tGSOrderAuditViewVO.getGs_order_detail_status();
                    tStr[8] = StringUtils.formatEDouble(tGSOrderAuditViewVO.getGs_goods_unitprice(), 4);
                    tStr[9] = tGSOrderAuditViewVO.getQuality_assure_period();
                    tStr[10] = tGSOrderAuditViewVO.getName_warehouse();
                    tStr[11] = m;
                    tStr[12] = tGSOrderAuditViewVO.getDrawing_piece_code();
                    tGSOrderVO.tList.add(tStr);
                } else {
                    // 订单编号不同创建新的订单VO对象
                    tGSOrderVO = new GSOrderVO();
                    tGSOrderVO.orderid = tGSOrderAuditViewVO.getGs_order_tempid_order();
                    // tGSOrderVO.category =
                    // GSBaseManager.getOrderCategoryName(tGSOrderAuditViewVO.category);
                    tGSOrderVO.orderCreateDate = tGSOrderAuditViewVO.getGs_order_create_date();
                    tGSOrderVO.orderDeptId = tGSOrderAuditViewVO.getGs_workcorp_id();
                    tGSOrderVO.orderDeptName = tGSOrderAuditViewVO.getName_warehouse();
                    tGSOrderVO.deliverMode = GSBaseManager.getDeliverModeName(tGSOrderAuditViewVO.getGs_deliver_mode());
                    tGSOrderVO.balanceMode = GSBaseManager.getBalanceModeName(tGSOrderAuditViewVO.getGs_balance_mode_order());
                    tGSOrderVO.orderStatus = GSBaseManager.getOrderStatusName(tGSOrderAuditViewVO.getGs_order_status());
                    tGSOrderVO.tList = new ArrayList();

                    String[] tStr = new String[13];
                    tStr[0] = tGSOrderAuditViewVO.getGs_concentricity_id();
                    tStr[1] = tGSOrderAuditViewVO.getName_product();
                    // tStr[2] =
                    // StringUtils.formatEDouble(tGSOrderAuditViewVO.manufacutreUnitPrice,2);
                    tStr[2] = tGSOrderAuditViewVO.getSpec();
                    tStr[3] = tGSOrderAuditViewVO.getModel();
                    tStr[4] = tGSOrderAuditViewVO.getProduct_brand();
                    tStr[5] = StringUtils.format(tGSOrderAuditViewVO.getGs_order_count(), 2) + tGSOrderAuditViewVO.getProduct_unit();
                    // tStr[4] =
                    // StringUtils.formatEDouble(tGSOrderAuditViewVO.manufacutreUnitPrice
                    // * tGSOrderAuditViewVO.orderCount,2);
                    // tStr[5] =
                    // GSBaseManager.getOrderDeptName(tGSOrderAuditViewVO.orderDeptId);
                    // tStr[6] =
                    // GSBaseManager.getProviderName(tGSOrderAuditViewVO.providerName);
                    tStr[6] = tGSOrderAuditViewVO.getGs_order_detail_id();
                    tStr[7] = tGSOrderAuditViewVO.getGs_order_detail_status();
                    tStr[8] = StringUtils.formatEDouble(tGSOrderAuditViewVO.getGs_goods_unitprice(), 4);
                    tStr[9] = tGSOrderAuditViewVO.getQuality_assure_period();
                    //tStr[10] = tGSOrderAuditViewVO.providerName;?????????????????????
                    tStr[10] = tGSOrderAuditViewVO.getName_warehouse();
                    tStr[11] = m;
                    tStr[12] = tGSOrderAuditViewVO.getDrawing_piece_code();
                    tGSOrderVO.tList.add(tStr);
                    tOrderId = tGSOrderAuditViewVO.getGs_order_tempid_order();
                    // 将订单VO对象放入结果集对象
                    tList.add(tGSOrderVO);
                }

            }
        }
        // 得到最后的订单列表
        return tList;
    }

    public String getAllReviewNeedOrderSql(GSOrderAuditQueryVO vo) {
        // 构造订单查询语句,条件:输入条件+状态为'已申请'+申请人不是自己
        StringBuffer tSql = new StringBuffer();
        tSql.append(" and ord.GS_ORDER_STATUS ='2' ");
        tSql.append(" and det.GS_ORDER_DETAIL_STATUS <> '21' ");
        if (vo.orderId != null && vo.orderId.trim().length() > 0) {
            tSql.append(" and ord.GS_ORDER_TEMPID like '%" + vo.orderId.trim() + "%'");
        }
        if(vo.drawingpiececode != null && !vo.drawingpiececode.equals("")){
            tSql.append(" and pro.DRAWING_PIECE_CODE like '%" + vo.drawingpiececode.trim() + "%'");
        }
        if (vo.deptId != null && vo.deptId.trim().length() > 0) {
            tSql.append(" and ord.GS_WORKCORP_ID like'" + vo.deptId + "%'");
        }
        if (vo.concentricityId != null && vo.concentricityId.trim().length() > 0) {
            tSql.append(" and det.GS_CONCENTRICITY_ID like '%" + vo.concentricityId.trim() + "%'");
        }
        if (vo.manufInfo != null && vo.manufInfo.trim().length() > 0) {
            tSql.append(" and (pro.NAME like '%" + vo.manufInfo.trim() + "%'");
            tSql.append(" or pro.MODEL like '%" + vo.manufInfo.trim() + "%'");
            tSql.append(" or pro.SPEC like '%" + vo.manufInfo.trim() + "%'");
            tSql.append(" or pro.PRODUCT_BRAND like '%" + vo.manufInfo.trim() + "%'");
            tSql.append(" or pro.APPENDER_PROPERTY like '%" + vo.manufInfo.trim() + "%'");
            tSql.append(" or pro.MANUFATURER like '%" + vo.manufInfo.trim() + "%')");
        }
        //是否只显示申沃售后服务部--90001
        if(vo.isSW!=null&&vo.isSW.equals("1")){
        	 tSql.append(" and  det.GS_PROVIDER_ID='90001' ");
        }
        if (!"".equals(vo.beginDate)) {
            tSql.append(" and to_char(to_date(ord.GS_ORDER_CREATE_DATE,'YYYY-MM-DD HH24:mi:ss'),'YYYY-MM-DD') >='" + vo.beginDate.replace('/', '-') + "'");
        }
        if (!"".equals(vo.endDate)) {
            tSql.append(" and to_char(to_date(ord.GS_ORDER_CREATE_DATE,'YYYY-MM-DD HH24:mi:ss'),'YYYY-MM-DD') <='" + vo.endDate.replace('/', '-') + "'");
        }
        tSql.append(" order by ord.GS_ORDER_CREATE_DATE desc");
        String sqls = this.aSql + tSql.toString();
        GSLogWriter.debug(this, sqls);
        return sqls;
    }

    /**
     * 得到所有需要复审的订单号
     * 
     * @param operatorId
     *            操作员id
     * @param operOrgId
     *            操作员所属机构id
     * @param orderId
     *            订单号,来自查询条件
     * @param orderCategory
     *            订单类型,来自查询条件
     * @param workCorpId
     *            下单机构,来自查询条件
     * @return 订单号列表
     * @throws GSException
     */
    public ArrayList getAllReviewNeedOrder(LoginContext operBean, GSOrderAuditQueryVO vo) throws GSException {
        GSOrderDAO ordd = new GSOrderDAO();
        if (vo.deptId == null || vo.deptId.length() == 0 || vo.deptId == null)
            throw new GSException(GSException.E10001, GSException.E10001_MSG);
        String tSql = this.getAllReviewNeedOrderSql(vo);
        // 执行订单查询,得到订单信息，包括订单号、产品代号和申请人代号
        ArrayList orderList = new ArrayList();
        try {
            orderList = ordd.executeQuery(new GSOrderAnaDetailBean(), tSql.toString(), null);
        } catch (Exception e) {
            throw new GSException(GSException.E10041, GSException.E10041_MSG);
        }
        // 根据过滤得有效订单组织订单显示对象
        ArrayList tList = new ArrayList();
        if (orderList.size() > 0) {
            String tOrderId = "";
            GSOrderVO tGSOrderVO = null;
            for (int i = 0; i < orderList.size(); i++) {
                GSOrderAnaDetailBean tGSOrderAuditViewVO = (GSOrderAnaDetailBean) orderList.get(i);
                // 判断新取得的OrderSubmitVO对象中的订单编号是否与前一对象中订单编号相同
                String m = DefineDic.getBalanceMode(tGSOrderAuditViewVO.getGs_balance_mode());
                if (tOrderId.equals(tGSOrderAuditViewVO.getGs_order_tempid_order())) {
                    // 订单编号相同则将取得的产品信息放入同一订单VO对象的ArrayList对象中
                    String[] tStr = new String[13];
                    tStr[0] = tGSOrderAuditViewVO.getGs_concentricity_id();
                    tStr[1] = tGSOrderAuditViewVO.getName_product();
                    // tStr[2] =
                    // StringUtils.formatEDouble(tGSOrderAuditViewVO.manufacutreUnitPrice,2);
                    tStr[2] = tGSOrderAuditViewVO.getSpec();
                    tStr[3] = tGSOrderAuditViewVO.getModel();
                    tStr[4] = tGSOrderAuditViewVO.getProduct_brand();
                    tStr[5] = StringUtils.format(tGSOrderAuditViewVO.getGs_order_count(), 2) + tGSOrderAuditViewVO.getProduct_unit();
                    // tStr[4] =
                    // StringUtils.formatEDouble(tGSOrderAuditViewVO.manufacutreUnitPrice
                    // * tGSOrderAuditViewVO.orderCount,2);
                    // tStr[5] =
                    // GSBaseManager.getOrderDeptName(tGSOrderAuditViewVO.orderDeptId);
                    // tStr[6] =
                    // GSBaseManager.getProviderName(tGSOrderAuditViewVO.providerName);
                    tStr[6] = tGSOrderAuditViewVO.getGs_order_detail_id();
                    tStr[7] = tGSOrderAuditViewVO.getGs_order_detail_status();
                    tStr[8] = StringUtils.formatEDouble(tGSOrderAuditViewVO.getGs_goods_unitprice(), 4);
                    tStr[9] = tGSOrderAuditViewVO.getQuality_assure_period();
                    tStr[10] = tGSOrderAuditViewVO.getName_warehouse();
                    tStr[11] = m;
                    tStr[12] = tGSOrderAuditViewVO.getDrawing_piece_code();
                    tGSOrderVO.tList.add(tStr);
                } else {
                    // 订单编号不同创建新的订单VO对象
                    tGSOrderVO = new GSOrderVO();
                    tGSOrderVO.orderid = tGSOrderAuditViewVO.getGs_order_tempid_order();
                    // tGSOrderVO.category =
                    // GSBaseManager.getOrderCategoryName(tGSOrderAuditViewVO.category);
                    tGSOrderVO.orderCreateDate = tGSOrderAuditViewVO.getGs_order_create_date();
                    tGSOrderVO.orderDeptId = tGSOrderAuditViewVO.getGs_workcorp_id();
                    tGSOrderVO.orderDeptName = tGSOrderAuditViewVO.getName_warehouse();
                    tGSOrderVO.deliverMode = GSBaseManager.getDeliverModeName(tGSOrderAuditViewVO.getGs_deliver_mode());
                    tGSOrderVO.balanceMode = GSBaseManager.getBalanceModeName(tGSOrderAuditViewVO.getGs_balance_mode_order());
                    tGSOrderVO.orderStatus = GSBaseManager.getOrderStatusName(tGSOrderAuditViewVO.getGs_order_status());
                    tGSOrderVO.tList = new ArrayList();

                    String[] tStr = new String[13];
                    tStr[0] = tGSOrderAuditViewVO.getGs_concentricity_id();
                    tStr[1] = tGSOrderAuditViewVO.getName_product();
                    // tStr[2] =
                    // StringUtils.formatEDouble(tGSOrderAuditViewVO.manufacutreUnitPrice,2);
                    tStr[2] = tGSOrderAuditViewVO.getSpec();
                    tStr[3] = tGSOrderAuditViewVO.getModel();
                    tStr[4] = tGSOrderAuditViewVO.getProduct_brand();
                    tStr[5] = StringUtils.format(tGSOrderAuditViewVO.getGs_order_count(), 2) + tGSOrderAuditViewVO.getProduct_unit();
                    // tStr[4] =
                    // StringUtils.formatEDouble(tGSOrderAuditViewVO.manufacutreUnitPrice
                    // * tGSOrderAuditViewVO.orderCount,2);
                    // tStr[5] =
                    // GSBaseManager.getOrderDeptName(tGSOrderAuditViewVO.orderDeptId);
                    // tStr[6] =
                    // GSBaseManager.getProviderName(tGSOrderAuditViewVO.providerName);
                    tStr[6] = tGSOrderAuditViewVO.getGs_order_detail_id();
                    tStr[7] = tGSOrderAuditViewVO.getGs_order_detail_status();
                    tStr[8] = StringUtils.formatEDouble(tGSOrderAuditViewVO.getGs_goods_unitprice(), 4);
                    tStr[9] = tGSOrderAuditViewVO.getQuality_assure_period();
                    //tStr[10] = tGSOrderAuditViewVO.providerName;?????????????????????
                    tStr[10] = tGSOrderAuditViewVO.getName_warehouse();
                    tStr[11] = m;
                    tStr[12] = tGSOrderAuditViewVO.getDrawing_piece_code();
                    tGSOrderVO.tList.add(tStr);
                    tOrderId = tGSOrderAuditViewVO.getGs_order_tempid_order();
                    // 将订单VO对象放入结果集对象
                    tList.add(tGSOrderVO);
                }
            }
        }
        // 得到最后的订单列表
        return tList;
    }

    /**
     * 根据订单号得到所需的订单细节(for订单核准)
     * 
     * @param orderId
     * @return
     * @throws GSException
     */
    public GSOrderVO getOrderAndManufactureForAuthorize(String orderId) throws GSException {
        GSOrderDAO tGSOrderDAO = new GSOrderDAO();
        GSProviderDAO tGSProviderDAO = new GSProviderDAO();
        GSOrderVO tGSOrderVO = new GSOrderVO();
        GSOrganizationDAO tGSOrganizationDAO = new GSOrganizationDAO();
        Connection tConn = null;
        try {
            tConn = tGSOrderDAO.getConnetion();
            // 根据订单编号查询订单对象和订单明细对象
            GSOrderBean orderBean = tGSOrderDAO.getOrderByTempID(orderId);
            tGSOrderVO.orderid = orderBean.getGs_order_tempid();
            tGSOrderVO.category = GSBaseManager.getOrderCategoryName(orderBean.getGs_order_category());
            tGSOrderVO.orderStatus = GSBaseManager.getOrderStatusName(orderBean.getGs_order_status());
            tGSOrderVO.tList = new ArrayList();
            tGSOrderVO.pList = new ArrayList();
            // 根据订单编号查询订单明细对象
            ArrayList tOrderDetailList = tGSOrderDAO.queryOrderAndDetailForAuthorize(tConn, orderId);
            if (tOrderDetailList.size() > 0) {
                String tOrderId = "";

                for (int i = 0; i < tOrderDetailList.size(); i++) {
                    GSOrderAuthorizeVO tGSOrderAuthorizeVO = (GSOrderAuthorizeVO) tOrderDetailList.get(i);
                    String[] tStr = new String[15];

                    tStr[0] = tGSOrderAuthorizeVO.detailId;
                    tStr[1] = tGSOrderAuthorizeVO.concentricityId;
                    tStr[2] = tGSOrderAuthorizeVO.manufactureId;
                    tStr[3] = tGSOrderAuthorizeVO.manufactureName;
                    tStr[4] = String.valueOf(tGSOrderAuthorizeVO.orderCount);
                    tStr[5] = tGSOrderAuthorizeVO.deliverDate;
                    tStr[6] = tGSOrderAuthorizeVO.deliverTime;
                    // tStr[7] = tGSOrderAuthorizeVO.orderDeptId;
                    // tStr[8] = tGSOrderAuthorizeVO.deliverAddr;
                    // tStr[9] = tGSOrderAuthorizeVO.contactName;
                    // tStr[10] = tGSOrderAuthorizeVO.contactPhone;
                    // tStr[11] = tGSOrderAuthorizeVO.deliverMode;
                    // tStr[12] = tGSOrderAuthorizeVO.balanceMode;
                    // tStr[13] = tGSOrderAuthorizeVO.orderid;
                    // tStr[14] =
                    // tGSOrganizationDAO.getOrg(tGSOrderAuthorizeVO.orderDeptId).getGs_org_name();
                    // 根据集中编码查询特约供应商/非特约供应商
                    ArrayList tempList = tGSProviderDAO.queryManufactureProvider(tConn, tGSOrderAuthorizeVO.concentricityId);
                    ArrayList provList = new ArrayList();
                    for (int j = 0; j < tempList.size(); j++) {
                        GSProviderBean tGSProviderBean = (GSProviderBean) tempList.get(j);
                        String[] pStr = new String[] { tGSProviderBean.getGs_provider_id(), tGSProviderBean.getGs_provider_name() };
                        provList.add(pStr);
                    }

                    tGSOrderVO.tList.add(tStr);
                    tGSOrderVO.pList.add(provList);
                }
            }
        } catch (GSException ge) {
            throw ge;
        } catch (Exception e) {
            GSLogWriter.debug(this, e.toString());
            throw new GSException(GSException.E10041, GSException.E10041_MSG);
        } finally {
            GSOrderDAO.close(tConn);
        }
        return tGSOrderVO;

    }

    /**
     * 根据订单号得到所需的订单细节(for订单审核)
     * 
     * @param aGSOrderVO
     * @return
     * @throws GSException
     */
    public GSOrderVO getOrderAndManufacture(String orderId) throws GSException {
        GSOrderDAO tGSOrderDAO = new GSOrderDAO();
        GSOrderVO tGSOrderVO = new GSOrderVO();
        Connection tConn = null;
        try {
            tConn = tGSOrderDAO.getConnetion();
            // 根据订单编号查询订单对象和订单明细对象
            GSOrderBean orderBean = tGSOrderDAO.getOrderByTempID(orderId);
            tGSOrderVO.orderid = orderBean.getGs_order_tempid();
            tGSOrderVO.category = GSBaseManager.getOrderCategoryName(orderBean.getGs_order_category());
            tGSOrderVO.orderStatus = GSBaseManager.getOrderStatusName(orderBean.getGs_order_status());
            tGSOrderVO.tList = new ArrayList();

            ArrayList tOrderDetailList = tGSOrderDAO.queryOrderAndDetail(tConn, orderId);
            if (tOrderDetailList.size() > 0) {
                String tOrderId = "";

                for (int i = 0; i < tOrderDetailList.size(); i++) {
                    GSOrderAuditVO tGSOrderAuditVO = (GSOrderAuditVO) tOrderDetailList.get(i);

                    String[] tStr = new String[11];
                    tStr[0] = tGSOrderAuditVO.orderid;
                    tStr[1] = "";
                    tStr[2] = "";
                    tStr[3] = tGSOrderAuditVO.detailId;
                    tStr[4] = tGSOrderAuditVO.manufactureId;
                    tStr[5] = tGSOrderAuditVO.manufactureName;
                    tStr[6] = String.valueOf(tGSOrderAuditVO.orderCount);
                    tStr[7] = GSBaseManager.getOrderDeptName(tGSOrderAuditVO.orderDeptId);
                    tStr[8] = tGSOrderAuditVO.concentricityId;
                    tStr[9] = GSBaseManager.getDeliverModeName(tGSOrderAuditVO.deliverMode);
                    tStr[10] = GSBaseManager.getBalanceModeName(tGSOrderAuditVO.balanceMode);

                    tGSOrderVO.tList.add(tStr);

                }
            }
        } catch (GSException ge) {
            throw ge;
        } catch (Exception e) {
            GSLogWriter.debug(this, e.toString());
            throw new GSException(GSException.E10041, GSException.E10041_MSG);
        } finally {
            GSOrderDAO.close(tConn);
        }
        return tGSOrderVO;
    }

    /**
     * 审核订单
     * 
     * @param indexs
     *            订单号
     * @param operId
     *            操作员id
     * @param category
     *            审核类型 0=初审 1=复审
     * @param bool
     *            是否审批通过，true表示通过，false表示不通过
     * @param msg
     *            审核意见
     * @throws GSException
     */
    public void auditOrder(String[] indexs, String operId, int category, boolean bool, boolean isSubmit, String msg) throws GSException {
        GSOrderDAO ordd = new GSOrderDAO();
        Connection conn = null;
        boolean tFlag = false;
        try {
            conn = ordd.getConnetion();
            conn.setAutoCommit(false);
            for (int i = 0; i < indexs.length; i++) {
                if (category == 0)
                    tFlag = ordd.firstAudit(indexs[i], operId, bool, msg, conn);//初审通过
                else
                    tFlag = ordd.review(indexs[i], operId, bool, isSubmit, msg, conn);//初审不通过
                if (!tFlag) {
                    GSLogWriter.debug(this, GSException.E19998_MSG);
                    conn.rollback();
                    break;
                }
            }
            conn.commit();

        } catch (GSException ge) {
            throw ge;
        } catch (Exception e) {
            GSLogWriter.error(this, e.toString());
            throw new GSException(GSException.E20054, GSException.E20054_MSG);
        } finally {
            try {
                conn.setAutoCommit(true);
            } catch (Exception e) {
            }
            GSOrderDAO.close(conn);
        }
    }

    /**
     * 审核不通过，不必记录修改内容
     * 
     * @param map
     * @param aBean
     * @throws GSException
     */
    public void unAuthorizeOrder(HashMap map, GSOperatorBean aBean) throws GSException {
        GSOrderDAO dao = new GSOrderDAO();
        GSOrderDetailDAO odd = new GSOrderDetailDAO();

        Connection conn = null;
        String sqlOrder = "update GS_ORDER set gs_order_status = 8,GS_AUTHORIZER_ID = ?,GS_AUTHORIZE_DATE = to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') where GS_ORDER_TEMPID =?";

        try {
            conn = odd.getConnetion();
            conn.setAutoCommit(false);
            PreparedStatement pstmt1 = conn.prepareStatement(sqlOrder);

            Iterator it = map.keySet().iterator();
            while (it.hasNext()) {
                String orderId = (String) it.next();
                pstmt1.setString(1, aBean.getGs_oper_id());
                pstmt1.setString(2, orderId);
                pstmt1.addBatch();
            }
            pstmt1.executeBatch();
            conn.commit();

        } catch (Exception e) {
            throw new GSException(GSException.E19999, GSException.E19999_MSG);
        } finally {
            try {
                conn.setAutoCommit(true);
            } catch (SQLException sqle) {

            }
            GSOrderDetailDAO.close(conn);
        }
    }

    /**
     * 审核订单
     * 
     * @param indexs
     *            订单号
     * @param operId
     *            操作员id
     * @param category
     *            审核类型 0=初审 1=复审
     * @param bool
     *            是否审批通过，true表示通过，false表示不通过
     * @param msg
     *            审核意见
     * @throws GSException
     */
    public void modifyOrder(LoginContext context, ArrayList ary) throws GSException {
        GSOrderDAO ordd = new GSOrderDAO();
        GSOrderDetailDAO orddd = new GSOrderDetailDAO();
        GSOperatorDAO operd = new GSOperatorDAO();
        GSManufactureProcessor proc = new GSManufactureProcessor();
        IDGenerator idg = new IDGenerator();
        Connection conn = null;
        boolean tFlag = false;
        try {
            conn = ordd.getConnetion();
            conn.setAutoCommit(false);

            String sql_a = "update GS_ORDER_DETAIL set GS_ORDER_DETAIL_STATUS=21,GS_LASTMODIFER_ID=?,GS_LASTMODIFY_CONTENTS=?,GS_LASTMODIFY_DATE=? where GS_ORDER_DETAIL_ID=?";
            PreparedStatement pstmt_a = conn.prepareStatement(sql_a);

            String sqlm = "insert into GS_ORDER_DETAIL (GS_ORDER_TEMPID,GS_ORDER_DETAIL_ID," + "GS_MANUFACTURE_ID,GS_CONCENTRICITY_ID,GS_ORDER_COUNT,"
                    + "GS_DELIVER_GOODS_DATE,GS_DELIVER_GOODS_TIME,GS_ORDER_DETAIL_STATUS,"
                    + "GS_PROVIDER_ID,GS_LASTMODIFER_ID,GS_LASTMODIFY_CONTENTS,GS_LASTMODIFY_DATE,"
                    + "GS_GOODS_UNITPRICE,gs_balance_mode) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
            PreparedStatement pstmtd = conn.prepareStatement(sqlm);

            String sqlo = "insert into GS_ORDER (GS_ORDER_TEMPID,GS_WORKCORP_ID," + "GS_ORDER_CATEGORY,GS_ORDER_STATUS,GS_NOTES,GS_RECORDER_ID,"
                    + "GS_ORDER_CREATE_DATE,GS_ORDER_SUM,GS_DELIVER_GOODS_ADDR," + "GS_ORDER_CONTACT_NAME,GS_ORDER_CONTACT_PHONE,"
                    + "GS_DELIVER_MODE,GS_BALANCE_MODE) values (?,?,0,?,?,?,?,?,?,?,?,?,?)";
            PreparedStatement pstmto = conn.prepareStatement(sqlo);

            // 构造生成时间
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String createDate = sdf.format(new Date(System.currentTimeMillis()));

            if (ary != null) {
                for (int i = 0; i < ary.size(); i++) {
                    GSOrderModifySaveVO vo = (GSOrderModifySaveVO) ary.get(i);

                    // 1 根据新输入的集中编码查询出优先产品
                    // modify 2006-11-23 直接根据产品编码查询
                    // GSManufactureBean mBean =
                    // proc.getManufactureByUnitPrice(vo.concentricityId);
                    GSManufactureBean mBean = proc.getManufactureDetail(vo.manufactureId);
                    // 2 根据vo中传入的申购单明细编号查询出申购单明细，并修改该明细为已取消
                    GSOrderDetailBean detailBean = orddd.queryOrderDetailByDetailId(conn, vo.orderDetailId);
                    pstmt_a.setString(1, context.getLoginUserId());
                    pstmt_a.setString(2, "订单信息修正");
                    pstmt_a.setString(3, createDate);
                    pstmt_a.setString(4, vo.orderDetailId);

                    pstmt_a.addBatch();
                    // 3 根据申购单明细查询出申购单
                    GSOrderBean orderBean = ordd.queryOrder(detailBean.getGs_order_temp_id(), conn);

                    // 4 构造新的订单号
                    long id = idg.generatorID(orderBean.getGs_workcorp_id(), "01");
                    int orderIdLength = orderBean.getGs_order_tempid().length() - 5;
                    String orderId = orderBean.getGs_order_tempid().substring(0, orderIdLength) + idg.formatID(id, 5);
                    // 5 新的订单必须初审
                    // 5.5 新的订单直接提交 2006-06-05
                    // String isReviewNeeded =
                    // "6";//"on".equals(vo.isReviewNeeded)?"3":"1";

                    // add by Jackey start
                    // 设置新定单以及明细数据状态=旧定单明细数据的状态
                    String isReviewNeeded = vo.orderDetailStatus;
                    // add by Jackey end

                    // 7 构造订单sql语句
                    pstmto.setString(1, orderId);
                    pstmto.setString(2, orderBean.getGs_workcorp_id());
                    pstmto.setString(3, isReviewNeeded);
                    pstmto.setString(4, "根据被修正的订单创建");
                    pstmto.setString(5, context.getLoginUserId());
                    pstmto.setString(6, createDate);
                    pstmto.setDouble(7, detailBean.getGs_goods_unitprice() * detailBean.getGs_deliver_goods_counts());
                    pstmto.setString(8, orderBean.getGs_deliver_goods_addr());
                    pstmto.setString(9, orderBean.getGs_order_contact_name());
                    pstmto.setString(10, orderBean.getGs_order_contact_phone());
                    pstmto.setString(11, orderBean.getGs_deliver_mode());
                    pstmto.setString(12, orderBean.getGs_balance_mode());
                    pstmto.addBatch();

                    // 10 构造新的订单明细信息号
                    String orderDetailId = orderId + idg.formatID(i, 2);
                    pstmtd.setString(1, orderId);
                    pstmtd.setString(2, orderDetailId);
                    pstmtd.setString(3, mBean.getGs_manufacture_id());
                    pstmtd.setString(4, vo.concentricityId);
                    pstmtd.setDouble(5, Double.parseDouble(vo.orderCount));
                    pstmtd.setString(6, vo.deliverGoodsDate);
                    pstmtd.setString(7, vo.deliverGoodsTime);
                    pstmtd.setString(8, isReviewNeeded);
                    pstmtd.setString(9, mBean.getGs_provider_id());
                    pstmtd.setString(10, context.getLoginUserId());
                    pstmtd.setString(11, "订单信息修正");
                    pstmtd.setString(12, createDate);
                    pstmtd.setDouble(13, mBean.getGs_manufacture_unitprice());
                    pstmtd.setString(14, vo.mode);
                    pstmtd.addBatch();

                }
                pstmt_a.executeBatch();
                pstmto.executeBatch();
                pstmtd.executeBatch();
            }

            conn.commit();

        } catch (Exception e) {
            GSLogWriter.error(this, e.toString());
            try {
                conn.rollback();
            } catch (SQLException ex) {
            }
            throw new GSException(GSException.E10043, GSException.E10043_MSG);
        } finally {
            try {
                conn.setAutoCommit(true);
            } catch (Exception e) {
            }
            GSOrderDAO.close(conn);
        }
    }

    public String saveDeliverOrder(GSOperatorBean bean, GSDeliverOrderSaveVO vo, ArrayList ary) throws GSException {
        GSOrderDAO dao = new GSOrderDAO();
        String orderId = dao.insert4Deliver(bean, vo, ary);
        return orderId;
    }

    /**
     * 查询一个订单的所有明细，用于订单录入
     * 
     * @param orderId
     * @return
     * @throws GSException
     */
    public ArrayList getDeliverOrderDetail(String orderId) throws GSException {
        ArrayList tList = new ArrayList();
        try {
            GSTempOrderDAO tGSTempOrderDAO = new GSTempOrderDAO();
            // 查询订单明细
            ArrayList tRs = tGSTempOrderDAO.queryOrderDetail_(orderId);
            if (tRs.size() > 0) {
                for (int i = 0; i < tRs.size(); i++) {
                    String[] tStr = new String[24];
                    GSOrderTempManufactureVO tGSOrderManufactureVO = (GSOrderTempManufactureVO) tRs.get(i);
                    // 取出订单包含的产品信息VO对象组成String数组
                    tStr[0] = tGSOrderManufactureVO.orderTempId;
                    tStr[1] = tGSOrderManufactureVO.orderDetailId;
                    tStr[2] = tGSOrderManufactureVO.workcorpId;
                    tStr[3] = tGSOrderManufactureVO.deliverMode;
                    tStr[4] = tGSOrderManufactureVO.balanceMode;
                    tStr[5] = tGSOrderManufactureVO.deliverGoodsId;
                    tStr[6] = tGSOrderManufactureVO.signinDate;
                    tStr[7] = tGSOrderManufactureVO.signinPerson;
                    tStr[8] = tGSOrderManufactureVO.deliverGoodsAddr;
                    tStr[9] = tGSOrderManufactureVO.deliveryMan;
                    tStr[10] = tGSOrderManufactureVO.deliverGoodsPhone;
                    tStr[11] = tGSOrderManufactureVO.signinExplain;

                    tStr[12] = tGSOrderManufactureVO.concentricityId;
                    tStr[13] = tGSOrderManufactureVO.manufactureId;
                    tStr[14] = tGSOrderManufactureVO.manufactureName;
                    tStr[15] = tGSOrderManufactureVO.orderCount;
                    tStr[16] = tGSOrderManufactureVO.spec == null ? "" : tGSOrderManufactureVO.spec;
                    tStr[17] = tGSOrderManufactureVO.type == null ? "" : tGSOrderManufactureVO.type;
                    tStr[18] = tGSOrderManufactureVO.brand == null ? "" : tGSOrderManufactureVO.brand;
                    tStr[19] = tGSOrderManufactureVO.quantUnit == null ? "" : tGSOrderManufactureVO.quantUnit;
                    tStr[20] = StringUtils.formatEDouble(tGSOrderManufactureVO.signinPrice, 4);
                    tStr[21] = tGSOrderManufactureVO.providerName;
                    tStr[22] = tGSOrderManufactureVO.deptName;
                    tStr[23] = tGSOrderManufactureVO.notes;

                    tList.add(tStr);
                }
            }
        } catch (GSException ge) {
            throw ge;
        } catch (Exception e) {
            GSLogWriter.error(this, e.toString());
            throw new GSException(GSException.E10042, GSException.E10042_MSG);
        }
        return tList;

    }

    /**
     * 订单签收
     * 
     * @param GSOperatorBean
     *            操作员Bean
     * @param ArrayList
     *            签收数据列表
     * @throws GSException
     */
    public String modifyOrder_r(LoginContext operBean, ArrayList ary) throws GSException {
        GSOrderDAO ordd = new GSOrderDAO();
        GSOrderDetailDAO orddd = new GSOrderDetailDAO();
        GSOperatorDAO operd = new GSOperatorDAO();
        GSManufactureProcessor proc = new GSManufactureProcessor();
        Connection conn = null;
        int err=0;
        int ok=0;
        String msg="";
        boolean tFlag = false;
        try {
            conn = ordd.getConnetion();
            conn.setAutoCommit(false);
            String sql_a = "update GS_ORDER_DETAIL set GS_SIGNIN_COUNT=?,GS_SIGNIN_DATE=?,GS_SIGNIN_PERSON=?,"
                    + "GS_SIGNIN_EXPLAIN=?,GS_ORDER_DETAIL_STATUS=? where GS_ORDER_DETAIL_ID =?";
            if (ary != null) {
                for (int i = 0; i < ary.size(); i++) {
                    GSOrderReceiveQueryVO vo = (GSOrderReceiveQueryVO) ary.get(i);
                    Object[] obj={String.valueOf(vo.cursigninCount),vo.cursigninDate,vo.signin_person,vo.signin_explain,GSBaseConstants.ORDER_DELIVERY_CONFIRM,vo.orderDetailId};
                    tFlag=ordd.executeUpdate(conn, sql_a, obj);
                    if (tFlag) {// 执行订单提交,将签收信息提交到APEP平台
                        String tRs = "";
                        tRs = GSCommunicationApepProcessor.sendOrderDetailSign(vo);
                        String[] result=GSCommunicationApepProcessor.parseReturnXml(tRs);
                        if (result[0].equals(GSBaseConstants.APEP_RETURN_SIGN_SUCCESS)){
                            conn.commit();
                            ok++;
                        }else{
                            conn.rollback();
                            err++;
                            GSLogWriter.error("订单签收提交数据失败");
                        }
                    }else{
                        conn.rollback();
                        throw new GSException("更新订单明细错误");
                    }
                }
                if (err==0) {
                    msg="有"+ok+"笔订单签收成功";
                }else{
                    msg="有"+ok+"笔订单签收成功,有"+err+"笔订单签收并提交到APEP失败。";
                }
            }
        } catch (Exception e) {
            GSLogWriter.error(this, e);
            try {
                conn.rollback();
            } catch (SQLException ex) {
            }
            throw new GSException(GSException.E10043, GSException.E10043_MSG);
        } finally {
            try {
                conn.setAutoCommit(true);
            } catch (Exception e) {
            }
            GSOrderDAO.close(conn);

        }
        return msg;
    }

    /**
     * 创建批次订单
     */
    public void creatNewBatchOrderDetail(ArrayList aList) throws GSException {
        GSOrderDetailDAO orddd = new GSOrderDetailDAO();
        orddd.creatNewBatchOrderDetail(aList);
    }
        
    public ArrayList getSubmitOrderAndDetail(GSOrderSubmitVO aGSOrderVO) throws GSException {
        ArrayList tOrderList = new ArrayList();
        GSOrderDAO tGSOrderDAO = new GSOrderDAO();
        ArrayList tList = new ArrayList();
            // 取得DB连接
            String[] tDateStr = new String[2];
            tDateStr[0] = aGSOrderVO.orderCreateDateStr;
            tDateStr[1] = aGSOrderVO.orderCreateDateEnd;
            tDateStr = DateUtil.formateDate(tDateStr);
            aGSOrderVO.orderCreateDateStr = tDateStr[0];
            aGSOrderVO.orderCreateDateEnd = tDateStr[1];
            // 查询所有订单及明细
            tOrderList = tGSOrderDAO.queryUncommitOrderAndDetail(this.aSql,aGSOrderVO);
            if (tOrderList.size() > 0) {
                String tOrderId = "";
                String tConCentricityId = "";
                GSOrderVO tGSOrderVO = null;
                for (int i = 0; i < tOrderList.size(); i++) {

                    GSOrderAnaDetailBean tGSOrderSubmitVO = (GSOrderAnaDetailBean) tOrderList.get(i);
                    String m = DefineDic.getBalanceMode(tGSOrderSubmitVO.getGs_balance_mode());
                    // 判断新取得的OrderSubmitVO对象中的订单编号是否与前一对象中订单编号相同
                    if (tOrderId.equals(tGSOrderSubmitVO.getGs_order_tempid())) {
                        // 订单编号相同则将取得的产品信息放入同一订单VO对象的ArrayList对象中
                        if (tConCentricityId.equals(tGSOrderSubmitVO.getGs_concentricity_id())) {
                            continue;
                        }
                        String[] tStr = new String[11];
                        tStr[0] = tGSOrderSubmitVO.getGs_concentricity_id();
                        tStr[1] = tGSOrderSubmitVO.getName_product();
                        tStr[2] = tGSOrderSubmitVO.getSpec();
                        tStr[3] = tGSOrderSubmitVO.getModel();
                        tStr[4] = tGSOrderSubmitVO.getProduct_brand();
                        tStr[5] = StringUtils.formatEDouble(tGSOrderSubmitVO.getGs_order_count(), 2);
                        tStr[6] = tGSOrderSubmitVO.getProduct_unit();
                        tStr[7] = tGSOrderSubmitVO.getGs_order_detail_id();
                        tStr[8] = GSBaseManager.getOrderDetailStatusName(tGSOrderSubmitVO.getGs_order_detail_status());
                        tStr[9] = m;
                        tStr[10] = tGSOrderSubmitVO.getDrawing_piece_code();
                        tGSOrderVO.tList.add(tStr);
                    } else {
                        // 订单编号不同创建新的订单VO对象
                        tGSOrderVO = new GSOrderVO();
                        tGSOrderVO.orderid = tGSOrderSubmitVO.getGs_order_tempid_order();
                        tGSOrderVO.orderStatus = GSBaseManager.getOrderStatusName(tGSOrderSubmitVO.getGs_order_status());
                        tGSOrderVO.orderDeptName = tGSOrderSubmitVO.getName_warehouse();
                        tGSOrderVO.deliverMode = GSBaseManager.getDeliverModeName(tGSOrderSubmitVO.getGs_deliver_mode());
                        tGSOrderVO.balanceMode = GSBaseManager.getBalanceModeName(tGSOrderSubmitVO.getGs_balance_mode_order());
                        tGSOrderVO.orderCreateDate = tGSOrderSubmitVO.getGs_order_create_date();
                        tGSOrderVO.recorderId = tGSOrderSubmitVO.getGs_recorder_id();
                        tGSOrderVO.orderDeptId = tGSOrderSubmitVO.getGs_workcorp_id();
                        tGSOrderVO.deliverGoodsAddr = tGSOrderSubmitVO.getGs_deliver_goods_addr();
                        tGSOrderVO.contactName = tGSOrderSubmitVO.getGs_order_contact_name();
                        tGSOrderVO.contactPhone = tGSOrderSubmitVO.getGs_order_contact_phone();
                        tGSOrderVO.notes = tGSOrderSubmitVO.getGs_notes();
                        tGSOrderVO.tList = new ArrayList();

                        String[] tStr = new String[11];
                        tStr[0] = tGSOrderSubmitVO.getGs_concentricity_id();
                        tStr[1] = tGSOrderSubmitVO.getName_product();
                        tStr[2] = tGSOrderSubmitVO.getSpec();
                        tStr[3] = tGSOrderSubmitVO.getModel();
                        tStr[4] = tGSOrderSubmitVO.getProduct_brand();
                        tStr[5] = StringUtils.formatEDouble(tGSOrderSubmitVO.getGs_order_count(), 2);
                        tStr[6] = tGSOrderSubmitVO.getProduct_unit();
                        tStr[7] = tGSOrderSubmitVO.getGs_order_detail_id();
                        tStr[8] = GSBaseManager.getOrderDetailStatusName(tGSOrderSubmitVO.getGs_order_detail_status());
                        tStr[9] = m;
                        tStr[10] = tGSOrderSubmitVO.getDrawing_piece_code();
                        tConCentricityId = tGSOrderSubmitVO.getGs_concentricity_id();
                        tGSOrderVO.tList.add(tStr);

                        tOrderId = tGSOrderSubmitVO.getGs_order_tempid_order();
                        // 将订单VO对象放入结果集对象
                        tList.add(tGSOrderVO);
                    }
                }
            }
        return tList;
    }
    
    /*******************智能补货业务**********************/
    private GSProductStorageDao pdao=new GSProductStorageDao();
    public ArrayList getProductSotrageViewList(GSOrderAuditQueryVO vo,String pageno,String pagesize) throws Exception{
        ArrayList list=pdao.getProductStorageViewListPage(vo, pageno, pagesize);
        ArrayList tempList=new ArrayList();
        for (int i = 0; i < list.size(); i++) {
            GSProductStorageApepBean temp=(GSProductStorageApepBean) list.get(i);
            String[] tstr=new String[18];
            tstr[0]=temp.getId();
            tstr[1]=temp.getWarehouse_name();
            tstr[2]=temp.getProduct_code();
            tstr[3]=temp.getName();
            tstr[4]=temp.getProduct_unit();
            tstr[5]=temp.getSpec();
            tstr[6]=temp.getModel();
            tstr[7]=temp.getProduct_brand();
            tstr[8]=temp.getProvider_name();
            tstr[9]=StringUtils.formatEDouble(temp.getProduct_price(),4);
            tstr[10]=StringUtils.formatEDouble(temp.getProduct_count(),2);
            tstr[11]=pdao.getStorageOutNum(temp.getProduct_code(),temp.getWarehouse_code());
            tstr[12]=DefineDic.getBalanceMode(temp.getBalance_mode());
            tstr[13]=temp.getWarehouse_code();
            tstr[14]=temp.getFill_count()+"";
            tstr[15]=temp.getMin_count()+"";
            tstr[16]=temp.getMax_count()+"";
            
            tempList.add(tstr);
        }
        return tempList;
    }
    
    public ArrayList getProductSotrageViewAllList(GSOrderAuditQueryVO vo) throws Exception{
        ArrayList list=pdao.getProductStorageViewList(vo);
        ArrayList tempList=new ArrayList();
        for (int i = 0; i < list.size(); i++) {
            GSProductStorageApepBean temp=(GSProductStorageApepBean) list.get(i);
            String[] tstr=new String[18];
            tstr[0]=temp.getId();
            tstr[1]=temp.getWarehouse_name();
            tstr[2]=temp.getProduct_code();
            tstr[3]=temp.getName();
            tstr[4]=temp.getProduct_unit();
            tstr[5]=temp.getSpec();
            tstr[6]=temp.getModel();
            tstr[7]=temp.getProduct_brand();
            tstr[8]=temp.getProvider_name();
            tstr[9]=StringUtils.formatEDouble(temp.getProduct_price(),4);
            tstr[10]=StringUtils.formatEDouble(temp.getProduct_count(),2);
            tstr[11]=pdao.getStorageOutNum(temp.getProduct_code(),temp.getWarehouse_code());
            tstr[12]=DefineDic.getBalanceMode(temp.getBalance_mode());
            tstr[13]=temp.getWarehouse_code();
            tstr[14]=temp.getFill_count()+"";
            tstr[15]=temp.getMin_count()+"";
            tstr[16]=temp.getMax_count()+"";
            tempList.add(tstr);
        }
        return tempList;
    }
    
    
    
    
    public int getProductSotrageCount(GSOrderAuditQueryVO vo)throws Exception{
        return pdao.getProductStorageViewCount(vo);
    }
    
    public ArrayList getSubmitOrderAndDetailAndProviderName(GSOrderSubmitVO aGSOrderVO) throws GSException {
        ArrayList tOrderList = new ArrayList();
        GSOrderDAO tGSOrderDAO = new GSOrderDAO();
        ArrayList tList = new ArrayList();
            // 取得DB连接
            String[] tDateStr = new String[2];
            tDateStr[0] = aGSOrderVO.orderCreateDateStr;
            tDateStr[1] = aGSOrderVO.orderCreateDateEnd;
            tDateStr = DateUtil.formateDate(tDateStr);
            aGSOrderVO.orderCreateDateStr = tDateStr[0];
            aGSOrderVO.orderCreateDateEnd = tDateStr[1];
            // 查询所有订单及明细
            tOrderList = tGSOrderDAO.queryUncommitOrderAndDetail(this.aSql,aGSOrderVO);
            if (tOrderList.size() > 0) {
                String tOrderId = "";
                String tConCentricityId = "";
                GSOrderVO tGSOrderVO = null;
                for (int i = 0; i < tOrderList.size(); i++) {

                    GSOrderAnaDetailBean tGSOrderSubmitVO = (GSOrderAnaDetailBean) tOrderList.get(i);
                    String m = DefineDic.getBalanceMode(tGSOrderSubmitVO.getGs_balance_mode());
                    // 判断新取得的OrderSubmitVO对象中的订单编号是否与前一对象中订单编号相同
                    if (tOrderId.equals(tGSOrderSubmitVO.getGs_order_tempid())) {
                        // 订单编号相同则将取得的产品信息放入同一订单VO对象的ArrayList对象中
                        if (tConCentricityId.equals(tGSOrderSubmitVO.getGs_concentricity_id())) {
                            continue;
                        }
                        String[] tStr = new String[12];
                        tStr[0] = tGSOrderSubmitVO.getGs_concentricity_id();
                        tStr[1] = tGSOrderSubmitVO.getName_product();
                        tStr[2] = tGSOrderSubmitVO.getSpec();
                        tStr[3] = tGSOrderSubmitVO.getModel();
                        tStr[4] = tGSOrderSubmitVO.getProduct_brand();
                        tStr[5] = StringUtils.formatEDouble(tGSOrderSubmitVO.getGs_order_count(), 2);
                        tStr[6] = tGSOrderSubmitVO.getProduct_unit();
                        tStr[7] = tGSOrderSubmitVO.getGs_order_detail_id();
                        tStr[8] = GSBaseManager.getOrderDetailStatusName(tGSOrderSubmitVO.getGs_order_detail_status());
                        tStr[9] = m;
                        tStr[10] = tGSOrderSubmitVO.getDrawing_piece_code();
                        tStr[11] = tGSOrderSubmitVO.getName();
                        tGSOrderVO.tList.add(tStr);
                    } else {
                        // 订单编号不同创建新的订单VO对象
                        tGSOrderVO = new GSOrderVO();
                        tGSOrderVO.orderid = tGSOrderSubmitVO.getGs_order_tempid_order();
                        tGSOrderVO.orderStatus = GSBaseManager.getOrderStatusName(tGSOrderSubmitVO.getGs_order_status());
                        tGSOrderVO.orderDeptName = tGSOrderSubmitVO.getName_warehouse();
                        tGSOrderVO.deliverMode = GSBaseManager.getDeliverModeName(tGSOrderSubmitVO.getGs_deliver_mode());
                        tGSOrderVO.balanceMode = GSBaseManager.getBalanceModeName(tGSOrderSubmitVO.getGs_balance_mode_order());
                        tGSOrderVO.orderCreateDate = tGSOrderSubmitVO.getGs_order_create_date();
                        tGSOrderVO.recorderId = tGSOrderSubmitVO.getGs_recorder_id();
                        tGSOrderVO.orderDeptId = tGSOrderSubmitVO.getGs_workcorp_id();
                        tGSOrderVO.deliverGoodsAddr = tGSOrderSubmitVO.getGs_deliver_goods_addr();
                        tGSOrderVO.contactName = tGSOrderSubmitVO.getGs_order_contact_name();
                        tGSOrderVO.contactPhone = tGSOrderSubmitVO.getGs_order_contact_phone();
                        tGSOrderVO.notes = tGSOrderSubmitVO.getGs_notes();
                        tGSOrderVO.tList = new ArrayList();

                        String[] tStr = new String[12];
                        tStr[0] = tGSOrderSubmitVO.getGs_concentricity_id();
                        tStr[1] = tGSOrderSubmitVO.getName_product();
                        tStr[2] = tGSOrderSubmitVO.getSpec();
                        tStr[3] = tGSOrderSubmitVO.getModel();
                        tStr[4] = tGSOrderSubmitVO.getProduct_brand();
                        tStr[5] = StringUtils.formatEDouble(tGSOrderSubmitVO.getGs_order_count(), 2);
                        tStr[6] = tGSOrderSubmitVO.getProduct_unit();
                        tStr[7] = tGSOrderSubmitVO.getGs_order_detail_id();
                        tStr[8] = GSBaseManager.getOrderDetailStatusName(tGSOrderSubmitVO.getGs_order_detail_status());
                        tStr[9] = m;
                        tStr[10] = tGSOrderSubmitVO.getDrawing_piece_code();
                        tStr[11] = tGSOrderSubmitVO.getName();
                        tConCentricityId = tGSOrderSubmitVO.getGs_concentricity_id();
                        tGSOrderVO.tList.add(tStr);

                        tOrderId = tGSOrderSubmitVO.getGs_order_tempid_order();
                        // 将订单VO对象放入结果集对象
                        tList.add(tGSOrderVO);
                    }
                }
            }
        return tList;
    }
 
    public ArrayList getSubmitOrderAndDetailAndProviderNameAndUserId(GSOrderSubmitVO aGSOrderVO) throws GSException {
        ArrayList tOrderList = new ArrayList();
        GSOrderDAO tGSOrderDAO = new GSOrderDAO();
        ArrayList tList = new ArrayList();
            // 取得DB连接
            String[] tDateStr = new String[2];
            tDateStr[0] = aGSOrderVO.orderCreateDateStr;
            tDateStr[1] = aGSOrderVO.orderCreateDateEnd;
            tDateStr = DateUtil.formateDate(tDateStr);
            aGSOrderVO.orderCreateDateStr = tDateStr[0];
            aGSOrderVO.orderCreateDateEnd = tDateStr[1];
            // 查询所有订单及明细
            tOrderList = tGSOrderDAO.queryUncommitOrderAndDetail(this.userSql,aGSOrderVO);
            if (tOrderList.size() > 0) {
                String tOrderId = "";
                String tConCentricityId = "";
                GSOrderVO tGSOrderVO = null;
                for (int i = 0; i < tOrderList.size(); i++) {

                    GSOrderAnaDetailBean tGSOrderSubmitVO = (GSOrderAnaDetailBean) tOrderList.get(i);
                    String m = DefineDic.getBalanceMode(tGSOrderSubmitVO.getGs_balance_mode());
                    // 判断新取得的OrderSubmitVO对象中的订单编号是否与前一对象中订单编号相同
                    if (tOrderId.equals(tGSOrderSubmitVO.getGs_order_tempid())) {
                        // 订单编号相同则将取得的产品信息放入同一订单VO对象的ArrayList对象中
                        if (tConCentricityId.equals(tGSOrderSubmitVO.getGs_concentricity_id())) {
                            continue;
                        }
                        String[] tStr = new String[12];
                        tStr[0] = tGSOrderSubmitVO.getGs_concentricity_id();
                        tStr[1] = tGSOrderSubmitVO.getName_product();
                        tStr[2] = tGSOrderSubmitVO.getSpec();
                        tStr[3] = tGSOrderSubmitVO.getModel();
                        tStr[4] = tGSOrderSubmitVO.getProduct_brand();
                        tStr[5] = StringUtils.formatEDouble(tGSOrderSubmitVO.getGs_order_count(), 2);
                        tStr[6] = tGSOrderSubmitVO.getProduct_unit();
                        tStr[7] = tGSOrderSubmitVO.getGs_order_detail_id();
                        tStr[8] = GSBaseManager.getOrderDetailStatusName(tGSOrderSubmitVO.getGs_order_detail_status());
                        tStr[9] = m;
                        tStr[10] = tGSOrderSubmitVO.getDrawing_piece_code();
                        tStr[11] = tGSOrderSubmitVO.getName();
                        tGSOrderVO.tList.add(tStr);
                    } else {
                        // 订单编号不同创建新的订单VO对象
                        tGSOrderVO = new GSOrderVO();
                        tGSOrderVO.orderid = tGSOrderSubmitVO.getGs_order_tempid_order();
                        tGSOrderVO.orderStatus = GSBaseManager.getOrderStatusName(tGSOrderSubmitVO.getGs_order_status());
                        tGSOrderVO.orderDeptName = tGSOrderSubmitVO.getName_warehouse();
                        tGSOrderVO.deliverMode = GSBaseManager.getDeliverModeName(tGSOrderSubmitVO.getGs_deliver_mode());
                        tGSOrderVO.balanceMode = GSBaseManager.getBalanceModeName(tGSOrderSubmitVO.getGs_balance_mode_order());
                        tGSOrderVO.orderCreateDate = tGSOrderSubmitVO.getGs_order_create_date();
                        tGSOrderVO.recorderId = tGSOrderSubmitVO.getGs_recorder_id();
                        tGSOrderVO.orderDeptId = tGSOrderSubmitVO.getGs_workcorp_id();
                        tGSOrderVO.deliverGoodsAddr = tGSOrderSubmitVO.getGs_deliver_goods_addr();
                        tGSOrderVO.contactName = tGSOrderSubmitVO.getGs_order_contact_name();
                        tGSOrderVO.contactPhone = tGSOrderSubmitVO.getGs_order_contact_phone();
                        tGSOrderVO.notes = tGSOrderSubmitVO.getGs_notes();
                        tGSOrderVO.tList = new ArrayList();

                        String[] tStr = new String[12];
                        tStr[0] = tGSOrderSubmitVO.getGs_concentricity_id();
                        tStr[1] = tGSOrderSubmitVO.getName_product();
                        tStr[2] = tGSOrderSubmitVO.getSpec();
                        tStr[3] = tGSOrderSubmitVO.getModel();
                        tStr[4] = tGSOrderSubmitVO.getProduct_brand();
                        tStr[5] = StringUtils.formatEDouble(tGSOrderSubmitVO.getGs_order_count(), 2);
                        tStr[6] = tGSOrderSubmitVO.getProduct_unit();
                        tStr[7] = tGSOrderSubmitVO.getGs_order_detail_id();
                        tStr[8] = GSBaseManager.getOrderDetailStatusName(tGSOrderSubmitVO.getGs_order_detail_status());
                        tStr[9] = m;
                        tStr[10] = tGSOrderSubmitVO.getDrawing_piece_code();
                        tStr[11] = tGSOrderSubmitVO.getName();
                        tConCentricityId = tGSOrderSubmitVO.getGs_concentricity_id();
                        tGSOrderVO.tList.add(tStr);

                        tOrderId = tGSOrderSubmitVO.getGs_order_tempid_order();
                        // 将订单VO对象放入结果集对象
                        tList.add(tGSOrderVO);
                    }
                }
            }
        return tList;
    }
}
